package xutil

import (
	"fmt"
	"strconv"
)

// 字符串转uint
func StrToUint(s string) uint {
	i := StrToInt(s)
	return uint(i)
}
func StrToUint64(s string) int64 {
	i := StrToInt(s)
	return int64(i)
}
func StrToInt64(s string) int64 {
	i := StrToInt(s)
	return int64(i)
}

func F接口转数字(i interface{}) int64 {
	str := InterToStr(i)
	return StrToUint64(str)
}

func F字符串转int8(str string) int8 {
	return int8(StrToInt(str))
}

// 字符串转int
func StrToInt(s string) int {
	if s == "" {
		return 0
	}
	i, e := strconv.Atoi(s)
	if e != nil {
		return 0
	}
	return i
}

// uint转string
func UintToString(n uint) string {
	return strconv.FormatUint(uint64(n), 10)
}

func InterToStr(i interface{}) string {
	return fmt.Sprintf("%v", i)
}

func IntToString(n int) string {
	return strconv.Itoa(n)
}

func F拼接参数(inter ...interface{}) (key string) {
	var ll string
	for range inter {
		ll += "%v"
	}
	key = fmt.Sprintf(ll, inter...) //先生成产品的key
	return
}
